import {
  createStore
} from 'vuex'
import axios from 'axios'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    objList: []
  },
  mutations: {
    add(state, value) {
      state.objList.push({
        value: value,
        id: new Date().getTime() + Math.random(),
        check: 0,
        time: new Date().toLocaleString(),
        checked: false,
      })
    },
    checkAll(state, value) {
      console.log(value);
      state.objList.forEach(item => {
        if (item.id == value) {
          item.checked = !item.checked
          if (item.check == 1) {
            item.check = 0
          } else {
            item.check = 1
          }

        }
      })
      console.log(state.objList);
    },
    off(state, value) {
      state.objList.forEach(item => {
        if (item.id == value) {
          if (item.check == 2) {
            item.check = 0
          } else {
            item.check = 2
          }
        }
      })
    }
  },


  actions: {


  },
  plugins: [persist()]


})